// 颜色相关操作

export function rgbToHex(r, g, b) {
  const htxStr = [r, g, b].map((x) => x.toString(16).padStart(2, '0')).join('');
  return `#${htxStr}`;
}

export function hexToRgb(hex) {
  return hex
    .replace(/^#?([a-f\d])([a-f\d])([a-f\d])$/i, (m, r, g, b) => `#${r}${r}${g}${g}${b}${b}`)
    .substring(1)
    .match(/.{2}/g)
    .map((x) => parseInt(x, 16));
}
